package de.uni.muenster.idw2.location.bluetooth.service;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * stores found BT-Devices with name (e.g. 00:19:63:FD:D9:7B) and signal strength in db
 * @author Andre Korzen
 *
 */
public class BluetoothDeviceData implements Parcelable {

	/**
	 * id of received BT-device like 00:19:63:FD:D9:7B
	 */
	String id;
	/**
	 * signal strength of received BT-device in dB (negative value)
	 */
	double db_value;
	private int floor;      //the floor
	private long time;      //time when the signal was received
	private int discoveryId; //a sequential id for discoveries. 
	private static int discoveryCount = 0; // sequence holder
	
	public BluetoothDeviceData(String name, double db, long time, int floor){
		this.setId(name);
		this.setDb_value(db);
		this.setFloor(floor);
		this.setTime(time);
		this.setDiscoveryId(discoveryCount);
	}
	
	public BluetoothDeviceData(BluetoothDeviceData dataToCopy){
	   this.setId(dataToCopy.getId());
	   this.setDb_value(dataToCopy.getDb_value());
	   this.setFloor(dataToCopy.getFloor());
	   this.setDiscoveryId(dataToCopy.getDiscoveryId());
	   this.setTime(dataToCopy.getTime());
	}

	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(getId());
		dest.writeDouble(getDb_value());
		dest.writeLong(getTime());
		dest.writeInt(getFloor());
		dest.writeInt(getDiscoveryId());
	}
	
	public static final Parcelable.Creator<BluetoothDeviceData> CREATOR
		    = new Parcelable.Creator<BluetoothDeviceData>() {
			public BluetoothDeviceData createFromParcel(Parcel in) {
			    return new BluetoothDeviceData(in);
			}
		
			public BluetoothDeviceData[] newArray(int size) {
			    return new BluetoothDeviceData[size];
			}
		};		
		private BluetoothDeviceData(Parcel in) {
		   //use the same sequence as before for writing 
		   setId(in.readString());
		   setDb_value(in.readDouble());
		   setTime(in.readLong());
		   setFloor(in.readInt());
		   setDiscoveryId(in.readInt());
		   
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getId() {
			return id;
		}

		public void setDb_value(double db_value) {
			this.db_value = db_value;
		}

		public double getDb_value() {
			return db_value;
		}
		
		public void setFloor(int floor) {
			this.floor = floor;
		}

		public int getFloor() {
			return floor;
		}

		public void setTime(long time) {
			this.time = time;
		}

		public long getTime() {
			return time;
		}

		private void setDiscoveryId(int discoveryId) {
			this.discoveryId = discoveryId;
			discoveryCount = (discoveryCount< getDiscoveryId())? getDiscoveryId(): discoveryCount;
		}

		public int getDiscoveryId() {
			return discoveryId;
		}
		
		public static void increaseDiscoveryCount(){
			discoveryCount ++;
		} 
}
